using System;

using NUnit.Framework;

using octalforty.Brushie.Web;

using octalforty.Waffle.ComponentModel.Navigation;
using octalforty.Waffle.ComponentModel.Navigation.Impl;

using octalforty.Waffle.ObjectModel.Business.Objects;

using Rhino.Mocks;

namespace octalforty.Waffle.UnitTests.ComponentModel.Navigation.Impl
{
    /// <summary>
    /// <see cref="UrlRewritingNavigationService"/> unit tests.
    /// </summary>
    [TestFixture()]
    public class UrlRewritingNavigationServiceTestFixture
    {
        [Test()]
        public void ResolveVirtualUrl()
        {
            MockRepository mockRepository = new MockRepository();
            IHttpRequestProvider httpRequestProvider;

            using(mockRepository.Record())
            {
                IHttpRequest httpRequest;
                httpRequest = mockRepository.CreateMock<IHttpRequest>();

                Expect.Call(httpRequest.ApplicationPath).Return("/application/path").Repeat.Any();
                Expect.Call(httpRequest.Url).Return(new Uri("http://www.site.com/application/path/signin")).Repeat.Any();

                httpRequestProvider = mockRepository.CreateMock<IHttpRequestProvider>();
                Expect.Call(httpRequestProvider.HttpRequest).Return(httpRequest).Repeat.Any();
            } // using

            using(mockRepository.Playback())
            {
                UrlRewritingNavigationService navigationService = new UrlRewritingNavigationService();
                navigationService.HttpRequestProvider = httpRequestProvider;

                Assert.AreEqual("http://www.site.com/application/path/signin", navigationService.ResolveVirtualUrl("~/signin"));
            } // using
        }

        [Test()]
        public void GetAccountControlPanelUrl()
        {
            INavigationService navigationService = new UrlRewritingNavigationService();

            Assert.AreEqual("~/forums/321/",
                navigationService.GetForumUrl(new Forum(321, "Tips & Tricks", "Tips & Tricks Forum Description")));
        }

        [Test()]
        public void GetDiscussionUrl()
        {
            INavigationService navigationService = new UrlRewritingNavigationService();

            Assert.AreEqual("~/forums/43/discussions/65/",
                navigationService.GetDiscussionUrl(new Discussion(65, "Hi there", new Forum(43, string.Empty, string.Empty))));
        }
    }
}
